﻿namespace EggOfPanKu.Library.Settings
{
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Linq;
    using System.Text;

    public class EggUserSettings : CustomSettingsBase
    {
        #region Fields

        private const string _configFileName = "eopk.config";
        private const string _configSectionName = "EggUserSettings";

        #endregion Fields

        #region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="EggUserSettings"/> class.
		/// </summary>
        public EggUserSettings()
        {
        }

        #endregion Constructors

        #region Properties

		/// <summary>
		/// Gets or sets the last deck played.
		/// </summary>
		/// <value>The last deck played.</value>
        [ConfigurationProperty("LastDeckPlayed")]
        public string LastDeckPlayed
        {
            get
            {
                string retVal = this["LastDeckPlayed"] as string;
                if (string.IsNullOrEmpty(retVal))
                {
                    retVal = "";
                    this["LastDeckPlayed"] = retVal;
                    this.Save();
                }

                return retVal;
            }
            set
            {
                this["LastDeckPlayed"] = value;
            }
        }

		/// <summary>
		/// Gets or sets the last IP address.
		/// </summary>
		/// <value>The last IP address.</value>
        [ConfigurationProperty("LastIPAddress")]
        public string LastIPAddress
        {
            get
            {
                string retVal = this["LastIPAddress"] as string;
                if (string.IsNullOrEmpty(retVal))
                {
                    retVal = "127.0.0.1";
                    this["LastIPAddress"] = retVal;
                    this.Save();
                }

                return retVal;
            }
            set
            {
                this["LastIPAddress"] = value;
            }
        }

		/// <summary>
		/// Gets or sets the last port number.
		/// </summary>
		/// <value>The last port number.</value>
        [ConfigurationProperty("LastPortNumber")]
        public string LastPortNumber
        {
            get
            {
                string retVal = this["LastPortNumber"] as string;
                if (string.IsNullOrEmpty(retVal))
                {
                    retVal = "18072";
                    this["LastPortNumber"] = retVal;
                    this.Save();
                }

                return retVal;
            }
            set
            {
                this["LastPortNumber"] = value;
            }
        }

		/// <summary>
		/// Gets or sets the name of the user nick.
		/// </summary>
		/// <value>The name of the user nick.</value>
        [ConfigurationProperty("UserNickName")]
        public string UserNickName
        {
            get
            {
                string retVal = this["UserNickName"] as string;
                if (string.IsNullOrEmpty(retVal))
                {
                    retVal = "Hantaisha-sama"; // Means Opponent
                    this["UserNickName"] = retVal;
                    this.Save();
                }

                return retVal;
            }
            set
            {
                this["UserNickName"] = value;
            }
        }

        /// <summary>
        /// Gets the name of the configuration file.
        /// </summary>
        /// <value>The name of the configuration file.</value>
        protected override string ConfigurationFileName
        {
            get { return _configFileName; }
        }

        /// <summary>
        /// Gets the name of the configuration section.
        /// </summary>
        /// <value>The name of the configuration section.</value>
        protected override string ConfigurationSectionName
        {
            get { return _configSectionName; }
        }

        #endregion Properties
	}
}